$(function () {
    $.ajax({
        url: bignew.user_detail,
        dataType: 'json',
        success: function (res) {
            console.log(res);
            if (res.code == 200) {
                $('#inputEmail1').val(res.data.username)
                $('#inputEmail2').val(res.data.nickname)
                $('.user_pic').val(res.data.userPic)
                $('#inputEmail3').val(res.data.email)
                $('#inputEmail4').val(res.data.password)
            }
        }
    })

    $('#exampleInputFile').on('change', function () {
        let myfile = this.files[0]

        let myurl = URL.createObjectURL(myfile)
        $('.user_pic').attr('src', myurl)
    })

    // 个人信息的编辑
    // 4、编辑用户信息
    // 请求地址：/admin/user/edit
    // 请求方式：post
    // 请求数据：使用formData提交

    $('.btn-edit').on('click', function () {
        console.log($('form').serialize());
        let formdata = new FormData($('#form')[0])
        console.log(...formdata);
        $.ajax({
            type: 'post',
            url: bignew.user_edit,
            data: formdata,
            processData: false,
            contentType: false,
            headers: {
                Authorization: localStorage.getItem('bignew_token_52')
            },
            dataType: 'json',
            success: function (res) {
                console.log(res);
                if (res.code == 200) {
                    alert(res.msg)
                    window.parent.location.href = './index.html'
                }
            }
        })
    })
})